<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>MyClouds：组织机构表单：新增</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../layuiadmin/lib/extend/eletree/eleTree.css" media="all">
		<style type="text/css">
			.eleTree {
				overflow: hidden;
				display: inline-block;
			}

			.myTree {
				border-left: 1px solid #ccc;
				border-right: 1px solid #ccc;
				border-bottom: 1px solid #ccc;
				height: auto;
				width: 100%;
				display: none;
				position: absolute;
				top: 100%;
				background-color: #fff;
				z-index: 100;
			}
		</style>
	</head>
	<body>

		<form class="layui-form" style="padding: 20px 30px 0 0;" lay-filter="org-form">
			<input type="hidden" name="parent_id" />
			<div class="layui-form-item">
				<label class="layui-form-label">上级组织</label>
				<div class="layui-input-block">
					<input type="text" name="parent_name" lay-verify="required" readonly class="layui-input">
					<div class="eleTree myTree" lay-filter="myData"></div>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">组织名称</label>
				<div class="layui-input-block">
					<input type="text" name="name" lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">组织类型</label>
				<div class="layui-input-block">
					<select name="type" lay-verify="required">
						<option value="1" selected>缺省</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">排序号</label>
				<div class="layui-input-block">
					<input type="number" name="sort_no" lay-verify="required" value="1" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">业务扩展码</label>
				<div class="layui-input-block">
					<input type="text" name="biz_code" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">扩展属性</label>
				<div class="layui-input-block">
					<textarea name="ext" placeholder="JSON字符串" autocomplete="off" class="layui-textarea"></textarea>
				</div>
			</div>
			<div class="layui-form-item layui-hide">
				<input type="button" lay-submit lay-filter="btn-add-submit" id="btn-add-submit" value="新增提交">
			</div>
		</form>
	</body>
	<script src="../../layuiadmin/layui/layui.js"></script>
	<script>
		var base = '../../layuiadmin/';
		layui.config({
			base: base
		}).extend({
			index: 'lib/index',
			eleTree: base + 'lib/extend/eletree/eleTree'
		}).use(['index', 'form', 'eleTree', 'myutil'], function() {
			var $ = layui.$,
				eleTree = layui.eleTree,
				myutil = layui.myutil,
				form = layui.form;
			myutil.init();
			var orgTree;
			$("input[name='parent_name']").on("click", function(e) {
				e.stopPropagation();
				if (!orgTree) {
					orgTree = eleTree.render({
						elem: '.myTree',
						contentType: 'application/json',
						method: 'post',
						url: layui.setter.my.surl + "admin/system/org/listTree",
						defaultExpandAll: false,
						defaultExpandedKeys: [1],
						expandOnClickNode: false
					});
				}
				$(".myTree").toggle();
			});
			eleTree.on("nodeClick(myData)", function(node) {
				$("input[name='parent_name']").val(node.data.currentData.label);
				$("input[name='parent_id']").val(node.data.currentData.id);
				$(".myTree").hide();
			});
			$(document).on("click", function() {
				$(".myTree").hide();
			});

			//新增
			form.on('submit(btn-add-submit)', function(data) {
				var win = parent.layer.getFrameIndex(window.name);
				myutil.ajax({
					url: layui.setter.my.surl + 'admin/system/org/add',
					data: data.field,
					ok: function(res) {
						layer.confirm(res.msg + '，继续新增下一个吗？', {
							icon: 1,
							yes: function(index) {
								layer.close(index);
								$("form [name='name']").val('');
								$("form [name='name']").focus();
								$("form [name='ext']").val('');
								$("form [name='biz_code']").val('');
							},
							btn2: function() {
								parent.layer.close(win);
							}
						});
						parent.layui.treeGrid.query('t-org');
					}
				});
			});

		});
	</script>

</html>
